package leetcode.社招.help;

import org.junit.Test;

import java.util.HashMap;
import java.util.Map;

/**
 * @author ：zsy
 * @date ：Created 2022/9/24 10:14
 * @description：
 */
public class Main {
    public static void main(String[] args) {

    }

    @Test
    public void test() {
        System.out.println(solution(
                new String[]{"insert", "addToValue", "get", "insert", "addToKey", "addToValue", "get"},
                new int[][]{{1, 2}, {2}, {1}, {2, 3}, {1}, {-1}, {3}}));
    }

    long solution(String[] queryType, int[][] query) {
        Map<Integer, Integer> map = new HashMap<>();
        int addValue = 0;
        int addKey = 0;
        int ans = 0;
        for (int i = 0; i < queryType.length; i++) {
            String qt = queryType[i];
            int[] q = query[i];
            switch (qt) {
                case "insert": {
                    map.put(q[0], q[1]);
                    continue;
                }
                case "addToValue": {
                    addValue += q[0];
                    continue;
                }
                case "get": {
                    ans += map.get(q[0] - addKey) + addValue;
                    continue;
                }
                case "addToKey": {
                    addKey += q[0];
                    continue;
                }
            }
        }
        return ans;
    }

}
